﻿using Microsoft.EntityFrameworkCore;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

namespace EasyDDD.Domain
{
    [Index(nameof(IsDeleted))]
    [Index(nameof(TenantId))]
    public abstract class Entity : IEntity
    {
        [Required]
        [Column(Order = 1)]
        [Comment("软删除")]
        public virtual bool IsDeleted { get; protected set; } = false;

        [Required]
        [Column(Order = 2)]
        [Comment("租户ID")]
        public virtual Guid TenantId { get; set; }

        [Comment("行版本")]
        [ConcurrencyCheck]
        public virtual Guid RowVersion { get; private set; } = default!;
    }

    public abstract class Entity<TKey> : Entity, IEntity<TKey>
    {
        [Key]
        //[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column(Order = 0)]
        [NotNull]
        [Comment("ID")]
        public virtual TKey Id { get; set; } = default!;
    }
}